package com.zs.propertymanage.handler;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.zs.propertymanage.annotation.SystemLog;
import com.zs.propertymanage.mapper.LogMapper;
import com.zs.propertymanage.mapper.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MsgLogHandler {

    @Autowired
    private MessageMapper messageMapper;
    @Autowired
    private LogMapper logMapper;

    //    @XxlJob("weekMsgHandler")  // 每周执行一次旧消息清除
    @XxlJob("weekMsgLogCleaner")  // 每周执行一次旧消息、旧日志清除
    @SystemLog(name = "每周清除旧消息/日志")
    public void deleteOldMsgLog() {
        XxlJobHelper.handleSuccess("每周旧消息/日志清除任务调度成功 " + new Date());
        System.err.println("[每周]旧消息/日志清除任务开始执行" + new Date());
        messageMapper.deleteOldMessages();  // 目前写的是清除30天以外的所有旧消息
        logMapper.deleteOldLog();   // 目前写的是清除7天以外的Get请求日志、登录/退出日志
        System.err.println("清除成功");
    }

}
